home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 2
/
SPACE - Library 2 - Volume 1.iso
/
music
/
7
/
modula
/
cube.mod
next >
Wrap
Text File
|
1985-11-19
|
5KB
|
186 lines
IMPLEMENTATION MODULE Cube;
(* throw up a rotating cube on the Atari 520 ST --- Chris Hall, 1985 *)
(* (c) TDI Software Ltd. 1985 Released by permission Les Caudle *)
FROM GEMVDIbase IMPORT
(* types *) VDIWorkInType, VDIWorkOutType ;
FROM VDIControls IMPORT
(* procs *) OpenVirtualWorkstation, CloseVirtualWorkstation ;
FROM VDIOutputs IMPORT
(* procs *) PolyLine ;
FROM VDIAttribs IMPORT
(* procs *) SetWritingMode, SetColour;
FROM AESGraphics IMPORT
(* procs *) GrafHandle;
CONST lines = 12; (* a cube has 12 lines *)
vertices = 8; (* and eight corners *)
maxNoLines = 100;
distance = 2000.0; (* viewing distance *)
addingX = 160.0; (* for centering image was 320 for mono *)
addingY = 100.0; (* was 200 for mono *)
sinphi = (* sin (PI/16) *) 0.195090322;
cosphi = (* cos (PI/16) *) 0.980785280;
TYPE LineSegment = ARRAY [0..3] OF INTEGER;
PolyLineType = ARRAY [1..lines] OF LineSegment;
VAR start,
finish : ARRAY [1..lines] OF CARDINAL;
x, y, z : ARRAY [1..vertices] OF REAL;
x2d, y2d : ARRAY [1..vertices] OF INTEGER;
whichArray : BOOLEAN;
polyLine : ARRAY BOOLEAN OF PolyLineType;
PROCEDURE XRotation;
VAR i : CARDINAL;
Y, Z : REAL;
BEGIN
FOR i := 1 TO vertices DO
Y := y [i]; Z := z [i];
y [i] := Y * cosphi - Z * sinphi;
z [i] := Z * cosphi + Y * sinphi;
END; (* FOR *)
END XRotation;
PROCEDURE YRotation;
VAR i : CARDINAL;
X, Z : REAL;
BEGIN
FOR i := 1 TO vertices DO
X := x [i]; Z := z [i];
x [i] := X * cosphi - Z * sinphi;
z [i] := Z * cosphi + X * sinphi;
END; (* FOR *)
END YRotation;
PROCEDURE ZRotation;
VAR i : CARDINAL;
X, Y : REAL;
BEGIN
FOR i := 1 TO vertices DO
X := x [i]; Y := y [i];
x [i] := X * cosphi - Y * sinphi;
y [i] := Y * cosphi + X * sinphi;
END; (* FOR *)
END ZRotation;
PROCEDURE DrawShape;
VAR i : INTEGER;
d : BOOLEAN;
BEGIN
d := NOT whichArray;
FOR i := 1 TO lines DO
polyLine [whichArray, i, 0] := x2d [start[i]];
polyLine [whichArray, i, 1] := y2d [start[i]];
polyLine [whichArray, i, 2] := x2d [finish[i]];
polyLine [whichArray, i, 3] := y2d [finish[i]];
PolyLine (handle, 2, polyLine [whichArray, i]); (* draw new cube *)
PolyLine (handle, 2, polyLine [d, i]); (* undraw old cube *)
END; (*FOR *)
whichArray := NOT whichArray;
END DrawShape;
PROCEDURE ConvertToXYpairs;
VAR i : CARDINAL;
f : REAL;
BEGIN
FOR i := 1 TO vertices DO
f := 1000.0 / (distance - z [i]);
x2d [i] := INTEGER(TRUNC( x [i] * f + addingX ));
y2d [i] := INTEGER(TRUNC( y [i] * f + addingY ));
END; (* FOR *)
END ConvertToXYpairs;
PROCEDURE SetPoints; (* put points into array *)
BEGIN
x [1] := -75.0; y [1] := 75.0; z [1] := 75.0;
x [2] := 75.0; y [2] := 75.0; z [2] := 75.0;
x [3] := 75.0; y [3] := -75.0; z [3] := 75.0;
x [4] := -75.0; y [4] := -75.0; z [4] := 75.0;
x [5] := -75.0; y [5] := 75.0; z [5] := -75.0;
x [6] := 75.0; y [6] := 75.0; z [6] := -75.0;
x [7] := 75.0; y [7] := -75.0; z [7] := -75.0;
x [8] := -75.0; y [8] := -75.0; z [8] := -75.0;
END SetPoints;
PROCEDURE SetLines;
BEGIN
start [1] := 1; finish [1] := 2;
start [2] := 2; finish [2] := 3;
start [3] := 3; finish [3] := 4;
start [4] := 4; finish [4] := 1;
start [5] := 1; finish [5] := 5;
start [6] := 2; finish [6] := 6;
start [7] := 3; finish [7] := 7;
start [8] := 4; finish [8] := 8;
start [9] := 5; finish [9] := 6;
start [10] := 6; finish [10] := 7;
start [11] := 7; finish [11] := 8;
start [12] := 8; finish [12] := 5;
END SetLines;
VAR c, d : CARDINAL;
b : BOOLEAN;
j : INTEGER;
handle : INTEGER;
In : VDIWorkInType;
Out : VDIWorkOutType;
PROCEDURE DoCube ;
BEGIN
FOR c := 0 TO 9 DO In [c] := 1 END;
In [10] := 2;
handle := GrafHandle (j, j, j, j);
OpenVirtualWorkstation (In, handle, Out);
j := SetWritingMode (handle, 3);
FOR b := FALSE TO TRUE DO
FOR c := 1 TO lines DO
FOR d := 0 TO 3 DO
polyLine [b, c, d] := 0
END;
END;
END;
whichArray := FALSE;
SetPoints;
SetLines;
FOR c := 1 TO 2 DO
YRotation;
ZRotation;
END; (* FOR *)
FOR c := 1 TO 1000 DO
XRotation;
ConvertToXYpairs;
DrawShape;
END;
CloseVirtualWorkstation (handle);
END DoCube ;
END Cube.
əəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəə